package com.cskaoyan.service.impl;

import com.cskaoyan.bean.CskaoyanmallSystem;
import com.cskaoyan.bean.CskaoyanmallSystemExample;
import com.cskaoyan.bean.vo.ConfigExpressVO;
import com.cskaoyan.bean.vo.ConfigMallVO;
import com.cskaoyan.bean.vo.ConfigOrderVO;
import com.cskaoyan.bean.vo.ConfigWXVO;
import com.cskaoyan.mapper.CskaoyanmallSystemMapper;
import com.cskaoyan.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConfigServieImpl implements ConfigService {
    @Autowired
    CskaoyanmallSystemMapper systemMapper;

    private void ChangeValueByName(String name, String voGet) {
        CskaoyanmallSystemExample cskaoyanmallSystemExample = new CskaoyanmallSystemExample( );
        CskaoyanmallSystemExample.Criteria criteria = cskaoyanmallSystemExample.createCriteria( );
        criteria.andKeyNameEqualTo(name);
        CskaoyanmallSystem cskaoyanmallSystem = new CskaoyanmallSystem( );
        cskaoyanmallSystem.setKeyValue(voGet);
        systemMapper.updateByExampleSelective(cskaoyanmallSystem, cskaoyanmallSystemExample);
    }

    private String SelectValueByName(String name) {
        CskaoyanmallSystemExample cskaoyanmallSystemExample = new CskaoyanmallSystemExample( );
        CskaoyanmallSystemExample.Criteria criteria = cskaoyanmallSystemExample.createCriteria( );
        criteria.andKeyNameEqualTo(name);
        List<CskaoyanmallSystem> cskaoyanmallSystems = systemMapper.selectByExample(cskaoyanmallSystemExample);
        CskaoyanmallSystem cskaoyanmallSystem = cskaoyanmallSystems.get(0);
        String value = cskaoyanmallSystem.getKeyValue( );
        return value;

    }

    public ConfigMallVO configMall() {
        ConfigMallVO configMallVO = new ConfigMallVO( );

        String cskaoyan_mall_mall_address = SelectValueByName("cskaoyan_mall_mall_address");
        configMallVO.setCskaoyanmall_mall_address(cskaoyan_mall_mall_address);
        String cskaoyan_mall_mall_name = SelectValueByName("cskaoyan_mall_mall_name");
        configMallVO.setCskaoyanmall_mall_name(cskaoyan_mall_mall_name);
        String cskaoyan_mall_mall_phone = SelectValueByName("cskaoyan_mall_mall_phone");
        configMallVO.setCskaoyanmall_mall_phone(cskaoyan_mall_mall_phone);
        String cskaoyan_mall_mall_qq = SelectValueByName("cskaoyan_mall_mall_qq");
        configMallVO.setCskaoyanmall_mall_qq(cskaoyan_mall_mall_qq);

        return configMallVO;
    }

    public ConfigExpressVO configExpress() {
        ConfigExpressVO configExpressVO = new ConfigExpressVO( );

        String cskaoyan_mall_express_freight_min = SelectValueByName("cskaoyan_mall_express_freight_min");
        configExpressVO.setCskaoyanmall_express_freight_min(cskaoyan_mall_express_freight_min);
        String cskaoyan_mall_express_freight_value = SelectValueByName("cskaoyan_mall_express_freight_value");
        configExpressVO.setCskaoyanmall_express_freight_value(cskaoyan_mall_express_freight_value);

        return configExpressVO;
    }

    public ConfigOrderVO configOrder() {
        ConfigOrderVO configOrderVO = new ConfigOrderVO( );

        String cskaoyan_mall_order_comment = SelectValueByName("cskaoyan_mall_order_comment");
        configOrderVO.setCskaoyanmall_order_comment(cskaoyan_mall_order_comment);
        String cskaoyan_mall_order_unconfirm = SelectValueByName("Cskaoyan_mall_order_unconfirm");
        configOrderVO.setCskaoyanmall_order_unconfirm(cskaoyan_mall_order_unconfirm);
        String cskaoyan_mall_order_unpaid = SelectValueByName("cskaoyan_mall_order_unpaid");
        configOrderVO.setCskaoyanmall_order_unpaid(cskaoyan_mall_order_unpaid);

        return configOrderVO;
    }

    public ConfigWXVO configWX() {
        ConfigWXVO configWXVO = new ConfigWXVO( );

        String cskaoyan_mall_wx_catlog_goods = SelectValueByName("cskaoyan_mall_wx_catlog_goods");
        configWXVO.setCskaoyanmall_wx_catlog_goods(cskaoyan_mall_wx_catlog_goods);
        String cskaoyan_mall_wx_catlog_list = SelectValueByName("cskaoyan_mall_wx_catlog_list");
        configWXVO.setCskaoyanmall_wx_catlog_list(cskaoyan_mall_wx_catlog_list);
        String cskaoyan_mall_wx_index_brand = SelectValueByName("cskaoyan_mall_wx_index_brand");
        configWXVO.setCskaoyanmall_wx_index_brand(cskaoyan_mall_wx_index_brand);
        String cskaoyan_mall_wx_index_hot = SelectValueByName("cskaoyan_mall_wx_index_hot");
        configWXVO.setCskaoyanmall_wx_index_hot(cskaoyan_mall_wx_index_hot);
        String cskaoyan_mall_wx_index_new = SelectValueByName("cskaoyan_mall_wx_index_new");
        configWXVO.setCskaoyanmall_wx_index_new(cskaoyan_mall_wx_index_new);
        String cskaoyan_mall_wx_index_topic = SelectValueByName("cskaoyan_mall_wx_index_topic");
        configWXVO.setCskaoyanmall_wx_index_topic(cskaoyan_mall_wx_index_topic);
        String cskaoyan_mall_wx_share = SelectValueByName("cskaoyan_mall_wx_share");
        configWXVO.setCskaoyanmall_wx_share(cskaoyan_mall_wx_share);

        return configWXVO;
    }

    @Override
    public void configExpressPost(ConfigExpressVO configExpressVO) {
        String name = "cskaoyan_mall_express_freight_min";
        ChangeValueByName(name, configExpressVO.getCskaoyanmall_express_freight_min( ));

        String name2 = "cskaoyan_mall_express_freight_value";
        ChangeValueByName(name2, configExpressVO.getCskaoyanmall_express_freight_value( ));
    }

    @Override
    public void configOrderPost(ConfigOrderVO configOrderVO) {
        String name = "cskaoyan_mall_order_comment";
        ChangeValueByName(name, configOrderVO.getCskaoyanmall_order_comment( ));

        String name2 = "cskaoyan_mall_order_unconfirm";
        ChangeValueByName(name2, configOrderVO.getCskaoyanmall_order_unconfirm( ));

        String name3 = "skaoyan_mall_order_unpaid";
        ChangeValueByName(name3, configOrderVO.getCskaoyanmall_order_unpaid( ));
    }

    @Override
    public void configMallPost(ConfigMallVO configMallVO) {
        String name = "cskaoyan_mall_mall_address";
        ChangeValueByName(name, configMallVO.getCskaoyanmall_mall_address( ));

        String name2 = "cskaoyan_mall_mall_name";
        ChangeValueByName(name2, configMallVO.getCskaoyanmall_mall_name( ));

        String name3 = "cskaoyan_mall_mall_phone";
        ChangeValueByName(name3, configMallVO.getCskaoyanmall_mall_phone( ));

        String name4 = "cskaoyan_mall_mall_qq";
        ChangeValueByName(name4, configMallVO.getCskaoyanmall_mall_qq( ));
    }

    @Override
    public void configWXPost(ConfigWXVO configWXVO) {
        String name = "cskaoyan_mall_wx_catlog_goods";
        ChangeValueByName(name, configWXVO.getCskaoyanmall_wx_catlog_goods( ));

        String name2 = "cskaoyan_mall_wx_index_topic";
        ChangeValueByName(name2, configWXVO.getCskaoyanmall_wx_index_topic( ));

        String name3 = "cskaoyan_mall_wx_index_brand";
        ChangeValueByName(name3, configWXVO.getCskaoyanmall_wx_index_brand( ));

        String name4 = "cskaoyan_mall_wx_index_hot";
        ChangeValueByName(name4, configWXVO.getCskaoyanmall_wx_index_hot( ));

        String name5 = "cskaoyan_mall_wx_index_new";
        ChangeValueByName(name5, configWXVO.getCskaoyanmall_wx_index_new( ));

        String name6 = "cskaoyan_mall_wx_index_topic";
        ChangeValueByName(name6, configWXVO.getCskaoyanmall_wx_index_topic( ));

        String name7 = "cskaoyan_mall_wx_share";
        ChangeValueByName(name7, configWXVO.getCskaoyanmall_wx_share( ));
    }


}
